/** 浅拷贝 */
export function clone(source) {
  if (!source) {
    return source
  }

  if (Array.isArray(source)) {
    return [...source]
  }

  if (typeof source === 'object') {
    return { ...source }
  }

  return source
}

/** 深拷贝 */
export function cloneDeep(source) {
  if (!source) {
    return source
  }

  if (Array.isArray(source)) {
    const arr = []
    source.forEach((item) => {
      arr.push(cloneDeep(item))
    })
    return arr
  }

  if (typeof source === 'object') {
    const obj = {}
    Object.entries(source).forEach(([k, v]) => {
      obj[k] = cloneDeep(v)
    })
    return obj
  }
  return source
}
